<!DOCTYPE html>
<html style="background-color:#fff;height:100%">
<head>
    <meta charset="UTF-8">
    <title>正中参编标准表单页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css" />
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/it/common/css/style.css" />
    <style>
        .thesis {
            width: 100%;
            height: 100%;
            padding: 0px;
            overflow-y: auto;
        }
        .thesis label {
            width: 30%!important;
        }
        .thesisbor>div {
            margin: 1% !important;
            padding: 0px 4% !important;
            width: 90% !important;
        }
        .thesis input {
            width: 140px!important;
            padding: 0px 0px 0px 10px!important;
        }

        .layui-form-select input {
            width: 152px !important;
            padding: 0px 0px 0px 10px !important;
        }
        .h34 {
            height: 34px;
        }
        .file-name-span {
            margin-top: 9px !important;
        }
    </style>
</head>
<body>
<!--新建文件夹-->
<form class="layui-form">
    <div class="layui-container" style="margin-top:40px;padding-bottom: 80px">
        <div class="thesis thesisTwo whitebg">
            <div class="ft20 bold">标准信息</div>
            <ul class="clearfix">
                <li class="clearfix h34">
                    <label class="fl gary">标准名称<span style="color: red">*</span>
                    </label>
                    <div class="fl">
                        <input type="hidden" name="spfId" value="${formData.spfId}" >
                        <input type="text" name="spfF1" value="${formData.spfF1}" lay-maxlength="128"
                          lay-verify="maxlength|required" autoComplete="off" placeholder="填写标准名称"/>
                    </div>

                </li>
                <li class="clearfix h34">
                    <label class="fl gary">状态</label>
                    <div class="fl">
                        <select name="spfF2">
                            <#list stateList as state>
                                <option value="${state.badtCode}" <#if (state.badtCode == formData.spfF2)> selected="selected" </#if> >${state.badtName}</option>
                            </#list>
                        </select>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">标准级别</label>
                    <div class="fl">
                        <select name="spfF3">
                            <#list bzjbList as bzjb>
                                <option value="${bzjb.badtCode}" <#if (bzjb.badtCode == formData.spfF3)> selected="selected" </#if> >${bzjb.badtName}</option>
                            </#list>
                        </select>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">标准编号<span style="color: red">*</span></label>
                    <div class="fl">
                        <input type="text" name="spfF4" value="${formData.spfF4}" lay-maxlength="128"
                               lay-verify="maxlength|required" autoComplete="off" placeholder="填写标准编号"/>
                    </div>
                </li>

                <li class="clearfix h34">
                    <label class="fl gary">标准委员会</label>
                    <div class="fl">
                        <select name="spfF5">
                            <#list bzwyhList as bzwyh>
                                <option value="${bzwyh.badtCode}" <#if (bzwyh.badtCode == formData.spfF5)> selected="selected" </#if> >${bzwyh.badtName}</option>
                            </#list>
                        </select>
                    </div>
                </li>


                <li class="clearfix h34">
                    <label class="fl gary">正中角色</label>
                    <div class="fl">
                        <select name="spfF6">
                            <#list zzjsList as zzjs>
                                <option value="${zzjs.badtCode}" <#if (zzjs.badtCode == formData.spfF6)> selected="selected" </#if> >${zzjs.badtName}</option>
                            </#list>
                        </select>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">正中单位排名<span style="color: red">*</span></label>
                    <div class="fl">
                        <input type="text" name="spfF7" value="${formData.spfF7}" lay-maxlength="128"
                               lay-verify="maxlength|required|number" autoComplete="off" placeholder="请填写正中单位排名"/>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">起草单位总数<span style="color: red">*</span></label>
                    <div class="fl">
                        <input type="text" name="spfF8" value="${formData.spfF8}" lay-maxlength="128"
                               lay-verify="maxlength|required|number" autoComplete="off" placeholder="请填起草单位总数"/>
                    </div>
                </li>
            </ul>
            <div>正中主要起草人</div>
            <ul class="clearfix">
                <ul class="clearfix zzbz" id="qcrs">
                    <li class="clearfix">
                        <label class="fl gary">姓名1<span style="color: red">*</span></label>
                        <div class="fl">
                            <input type="text" name="formDataList[0].data1" lay-maxlength="128"
                                   lay-verify="maxlength|required" value="${qicaorens[0].data1}" autoComplete="off" placeholder="填写姓名1"/>
                        </div>
                    </li>
                    <li class="clearfix">
                        <label class="fl gary">排名<span style="color: red">*</span></label>
                        <div class="fl">
                            <input type="text" name="formDataList[0].data2" lay-maxlength="128"
                                   lay-verify="maxlength|required|number" value="${qicaorens[0].data2}"
                                   placeholder="填写排名"/>
                            <img src="/plugin/common/images/77@2x.png" onclick="zzbzadd()" class="thesisimg2">
                            <#--                        <img src="/plugin/common/images/76@2x.png" class="thesisimg1">-->
                        </div>
                    </li>
                </ul>

                <#list qicaorens as qicaoren>
                    <#if (qicaoren_index > 0)>
                        <ul class="zzbz">
                            <li class="clearfix">
                                <label class="fl gary">姓名<span class="ind">${qicaoren_index+1}</span></label>
                                <div class="fl">
                                    <input class="zb-input" type="text" value="${qicaoren.data1}"
                                           name="formDataList[${qicaoren_index}].data1"
                                           placeholder="填写姓名${qicaoren_index+1}"/>
                                </div>
                            </li>
                            <li class="clearfix">
                                <label class="fl gary">排名<span class="ind">${qicaoren_index+1}</span></label>
                                <div class="fl">
                                    <input class="zb-inputs" type="text" value="${qicaoren.data2}"
                                           name="formDataList[${qicaoren_index}].data2"
                                           placeholder="填写排名${qicaoren_index+1}"/>
                                    <img src="/plugin/common/images/76@2x.png" onclick="zzbzClick(this)"
                                         class="thesisimg1">
                                </div>
                            </li>
                        </ul>
                    </#if>
                </#list>

                <li class="clearfix h34">
                    <label class="fl gary">发布单位</label>
                    <div class="fl">
                        <input type="text" name="spfF9" value="${formData.spfF9}" lay-maxlength="128"
                               lay-verify="maxlength" placeholder="填写发布单位"/>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">发布时间<span style="color: red">*</span></label>
                    <div class="fl">
                        <input type="text" name="spfF10" id="spfF10" lay-maxlength="128" lay-verify="maxlength|required"
                               value="${formData.spfF10}" autoComplete="off" placeholder="填写发布时间"/>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">实施时间<span style="color: red">*</span></label>
                    <div class="fl">
                        <input type="text" name="spfF11" id="spfF11" lay-maxlength="128" lay-verify="maxlength|required"
                               value="${formData.spfF11}" autoComplete="off" placeholder="填写实施时间"/>
                    </div>
                </li>
                <li class="clearfix h34">
                    <label class="fl gary">牵头单位名称</label>
                    <div class="fl">
                        <input type="text" name="spfF12" value="${formData.spfF12}" lay-maxlength="128"
                               lay-verify="maxlength" placeholder="填写牵头单位名称"/>
                    </div>
                </li>
                <li class="clearfix" style="width: 90%">
                    <label class="fl gary" style="width: 15%!important;">标准</label>
                    <div class="fl" style="width: 70%!important;padding-left: 2%">
                        <div>
                            <img id="1100010001" src="/plugin/common/images/57@2x.png" class="thesisimg3 file-upload"
                                 filedata="{'type':'1100010001','superiorId':'${parentDicId}'}">
                            <span class="blue">上传文件</span>
                        </div>
                        <div class="thesisbor" style="width: 100%!important;">

                        </div>
                    </div>
                </li>
                <ul class="clearfix h34"></ul>
                <ul class="clearfix h34"></ul>
                <li class="clearfix">
                    <label class="fl gary" style="width: 15%!important;">备注</label>
                    <div class="fl" style="width: 60%!important;">
                        <textarea name="spfF13" lay-maxlength="200" lay-verify="maxlength" rows="" cols=""
                                  style="width: 100%!important;">${formData.spfF13}</textarea>
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-footer"
         style="width: 100%;text-align: center;background-color: #fff;position:fixed;bottom:0px;height: 50px;padding-top: 15px">
        <input class="layui-btn layui-btn-primary layui-btn-sm" type="button" value="关闭"
               onclick="_itkl.content.layerClose()">
        <input id="sub-btn" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="formDemo"
               type="button" value="确定">
    </div>
</form>
<!--JQ-->
<script type="text/javascript" charset="utf-8" src="/plugin/common/js/jquery-1.8.3.min.js"></script>
<!--公用样式JS-->
<script type="text/javascript" charset="utf-8" src="/plugin/common/js/comment.js"></script>
<!--选择城市js-->
<script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/it/common/js/itkl.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/common/js/form.file.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script>
    var dicId = '${dicId}';
    var formCode = '${formCode}';
    var temp = '${temp}';
    var fileCount = '${fileCount}';
    var edit = '${edit}';
    var deledFileIds = [];
    layui.use(['form', 'layer', 'upload', 'element', 'table'], function () {
        var form = layui.form, layer = layui.layer, laydate = layui.laydate;
        laydate.render({//发布时间
            elem: '#spfF10',
            event: 'click'
        })
        laydate.render({//实施时间
            elem: '#spfF11',
            event: 'click'
        })
        form.verify({
            maxlength: function (v, item) {
                var maxlength = item.getAttribute('lay-maxlength');
                if (v.trim() != '') {
                    if (v.trim().length > maxlength) {
                        return "输入长度不能大于" + maxlength + "个字符！";
                    }
                }
            },
            number: function (v) {
                var reg = /^[0-9]*$/;
                var flag = reg.test(v.trim());
                if (!flag) {
                    return '请输入正确的数字';
                }
            },
            decimal: function (v) {
                var reg = /^-?([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,10})?$/;
                var flag = reg.test(v.trim());
                if (!flag) {
                    return '请输入正确的金额';
                }
            },
            perdecimal: function (v) {
                var reg = /^[1-9][0-9]*([.][0-9]+)?$/;
                var flag = reg.test(v.trim());
                if (!flag) {
                    if (v.trim() != "0" || v.trim() != 0) {
                        return '请输入数字';
                    }
                }
            }
        })

        //提交
        form.on('submit(formDemo)', function (data) {
            $('#sub-btn').attr('disabled', 'disabled');
            data.field.spfF29 = dicId;
            data.field.spfF30 = formCode;
            if (deledFileIds && deledFileIds.length > 0) {
                for (var a = 0; a < deledFileIds.length; a++) {
                    data.field['strList9[' + a + ']'] = deledFileIds[a];
                }
            }
            var json = data.field;
            if (json) {
                layerAjax("/it/form/insertBook", json, '', function (d) {
                    if (d) {
                        layer.msg(d.msg, {icon: 1})
                        setTimeout(function () {
                            parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        },1000);
                    }else{
                        $('#sub-btn').removeAttr('disabled');
                        layer.msg(d.msg,{icon:2})
                    }
                })
            }
        })


    })

    function zzbzadd() {
        var len = $(".zzbz").length;
        var num = len + 1;
        $(".zzbz:last").after('<ul class="zzbz"><li class="clearfix">\n' +
            '                    <label class="fl gary">姓名<span style="color: red">*</span><span class="ind">' + num + '</span></label>\n' +
            '                    <div class="fl">\n' +
            '                        <input class="zb-input" type="text" lay-maxlength="128" lay-verify="maxlength|required" name="formDataList[' + len + '].data1" placeholder="填写姓名' + num + '"/>\n' +
            '                    </div>\n' +
            '                </li>\n' +
            '                <li class="clearfix">\n' +
            '                    <label class="fl gary">排名<span style="color: red">*</span></label>\n' +
            '                    <div class="fl">\n' +
            '                        <input class="zb-inputs" type="text" lay-maxlength="128" lay-verify="maxlength|required|number" name="formDataList[' + len + '].data2" placeholder="填写排名"/>\n' +
            '                        <img src="/plugin/common/images/76@2x.png" onclick="zzbzClick(this)" class="thesisimg1">\n' +
            '                    </div>\n' +
            '                </li></ul>');
    }

    function zzbzClick(b) {
        $(b).parent().parent().parent().remove();
        zbflushChildsInd();
    }

    function zbflushChildsInd() {
        $.each($('.zzbz'), function (i, e) {
            var num = (i * 1);
            $(e).find('.ind').text(num + 1);
            $(e).find('.zb-input').attr('placeholder', '填写姓名' + (num + 1));
            $(e).find('.zb-input').attr('name', 'formDataList[' + num + '].data1');
            $(e).find('.zb-inputs').attr('placeholder', '填写排名' + (num + 1));
            $(e).find('.zb-inputs').attr('name', 'formDataList[' + num + '].data2');

        })
    }

    $(function () {
        // fileType,elem,url,container,before,choose,done,error,multiple,accept,exts,size,auto
        var tempFileIds = [];
        var uploadFileAdds = $('.file-upload');
        if (uploadFileAdds && uploadFileAdds.length > 0) {
            bindOneUploader(uploadFileAdds, 0);
        }

        if (edit && edit == '1') {
            initFileShow();
        }

    })

    //显示上传的文件:
    function initFileShow() {
        var uploadFileAdds = $('.file-upload');
        initOneFileShow(uploadFileAdds, 0);
    }

    function initOneFileShow(uploadFileAdds, i) {
        var aFileUploadAdd = $(uploadFileAdds[i]);
        var fileDataStr = aFileUploadAdd.attr('filedata');
        var fileData = eval('(' + fileDataStr + ')');
        var fileContainer = aFileUploadAdd.parent().next();
        var type = fileData.type;
        if (edit && edit == '1') {
            fileData.spfId = '${formData.spfId}';
        }
        layerAjaxGetIT('/it/form/getFileList', {
            dicId: dicId,
            formFileType: type,
            spfId: '${formData.spfId}'
        }, '', uploadFileAdds, i, function (res) {
            if (res.flag) {
                //显示:
                showFile(res.data, fileContainer, 0);
            }
        })
    }

    function showFile(filelist, container, ind) {
        if (filelist && filelist.length > 0 && (ind < filelist.length)) {
            var aFile = filelist[ind];
            var newFileId = aFile.id;
            var newIndex = $('.form-file-div-' + aFile.type).length * 1;
            var fileName = '';
            if (aFile.type == '1100010001') {
                fileName = 'strList1';
            }
            container.prepend('<div class="clearfix form-file-div form-file-div-' + aFile.type + '">\n' +
                '                            <span class="fl file-name-span">' + aFile.fileName + '</span>\n' +
                '                            <img src="/plugin/common/images/89@2x.png" class="fr cursor" onclick="_form_file.del.delReal(this,' + '&apos;' + aFile.id + '&apos;' + ',' + '&apos;' + aFile.type + '&apos;' + ',deledFileIds)">\n' +
                '                            <input type="hidden" class="' + aFile.type + '-input" name="' + fileName + '[' + newIndex + ']" value="' + newFileId + '" />' +
                '                        </div>');
            ind ++;
            showFile(filelist,container,ind);
        }
    }

    //绑定上传组件单个
    function bindOneUploader(uploadFileAdds,i){
        var aFileUploadAdd = $(uploadFileAdds[i]);
        var id=aFileUploadAdd.attr('id');
        var fileDataStr = aFileUploadAdd.attr('filedata');
        var fileData = eval('(' + fileDataStr + ')');
        if(edit && edit == '1'){
            fileData.spfId = '${formData.spfId}';
        }

        var fileContainer = aFileUploadAdd.parent().next();
        var type = fileData.type;
        var ext = '';
        var fileName = '';
        if(type == '1100010001'){
            //书著文件,只能上传文档
            ext = 'pdf';
            fileName = 'strList1';
        }
        //上传组件参数自定义:
        var uploadPara = {
            elem: '#'+id,
            temp: temp,
            exts: ext,
            before: function(res){
                this.data = fileData;
            },
            container: fileContainer,
            fileName: fileName,
            // fileOrder: 'desc'
        };
        _form_file.upload.bind(uploadPara);
        if(i < uploadFileAdds.length-1){
            i++;
            bindOneUploader(uploadFileAdds,i);
        }
    }

</script>

</body>

</html>
